package com.igeek.service;

import com.igeek.dao.UserDao;
import com.igeek.domain.User;

import java.sql.SQLException;

public class UserService {
    private UserDao userDao=new UserDao();

    public boolean register(User user){
        try {
            int resullt=userDao.insert(user);
            return resullt>0?true:false;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public void active(String activeCode) {
        try {
            userDao.active(activeCode);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public boolean isExist(String name){
        User user=null;
        try {
            user=userDao.getUserByName(name);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user!=null?true:false;
    }

    public User login(User user){
        User existUser=null;
        try {
            existUser=userDao.login(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return existUser;
    }
}
